import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_device_type/flutter_device_type.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tv_friso_screen/forgot_password_phone_pad_page.dart';
import 'package:tv_friso_screen/home_page_tv.dart';
import 'package:tv_friso_screen/utils/result_check_utils.dart';
import 'package:tv_friso_screen/utils/share_pre_utils.dart';

import 'data_model/token_bean.dart';
import 'home_page_pad.dart';
import 'home_page_phone.dart';
import 'model/response_with_object.dart';
import 'net/api_address.dart';
import 'net/data_helper.dart';
import 'net/http_manager.dart';

class LoginPhonePadPage extends StatefulWidget {
  const LoginPhonePadPage({super.key});

  @override
  State<LoginPhonePadPage> createState() => _LoginPhonePadPageState();
}

class _LoginPhonePadPageState extends State<LoginPhonePadPage> {
  var phoneController = TextEditingController();
  var pwdController = TextEditingController();
  var loginController = TextEditingController();

  FocusNode focusNodeUser = FocusNode();
  FocusNode focusNodePwd = FocusNode();
  FocusNode focusNodeLogin = FocusNode();
  var currentLanguage = '';
  var isTable = false;

  //登录
  void postLogin() async {
    var device = await _getDeviceId();
    var params = {
      "login_account": phoneController.text,
      "password": pwdController.text,
      "device": device
    };
    var formData = DataHelper.getBaseMapWithParamsWithoutToken(
        params); //DataHelper.getBaseMapParamsWithoutToken(params);
    var response =
        await HttpManager().post(ApiAddress.postLogin, params: formData);

    if (mounted) {
      if (response['data'] != null &&
          response['code'] == HttpManager.codeSuccess) {
        ResponseWithObject<TokenBean> data =
            ResponseWithObject.fromJson(response as Map<String, dynamic>, (j) {
          if (j != null) {
            return TokenBean.fromJson(j);
          } else {
            return j;
          }
        });

        //给Token赋值
        SharePreUtils.setToken(data.data.accessToken);

        String type = await getDeviceType();
        //跳转首页
        identifyDevice(type);
      } else {
        ResultCheckUtils.checkResult(
            context, response['code'], response['msg']);
      }
    }
  }

  Future<String> _getDeviceId() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    String deviceId;

    if (Theme.of(context).platform == TargetPlatform.iOS) {
      var iosInfo = await deviceInfo.iosInfo; // 获取 iOS 设备信息
      deviceId = iosInfo.identifierForVendor!;
    } else {
      var androidInfo = await deviceInfo.androidInfo; // 获取 Android 设备信息
      deviceId = androidInfo.id; // 使用 Android ID
    }
    return deviceId;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    // phoneController.text = "15514530862";
    // pwdController.text = "Fcg123456";
    loginController.text = "登 录";

    //使用 post-frame callback 确保焦点请求在构建后执行
    WidgetsBinding.instance.addPostFrameCallback((_) {
      FocusScope.of(context).requestFocus(focusNodeUser);
    });

    // 获取当前的语言环境
    currentLanguage = SharePreUtils.getLanguage();
    isTable = Device.get().isTablet;

    /*focusNodeUser.addListener(() {
      if (focusNodeUser.hasFocus) {
        print('Username field focused');
      }
    });

    focusNodePwd.addListener(() {
      if (focusNodePwd.hasFocus) {
        print('pwd field focused');
      }
    });*/
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      //false: 输入框抵住键盘   true:重新计算view的高度 适应软键盘弹出时 输入框在软键盘上方 不遮挡
      body: Stack(
        children: [
          Visibility(
            visible: currentLanguage == "zh",
            child: Container(
              width: double.infinity,
              height: double.infinity,
              alignment: Alignment.center,
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(
                    "assets/images/icon_bg_login.jpg",
                  ),
                  fit: BoxFit.fill,
                ),
              ),
              child: Stack(
                children: [
                  SizedBox(
                    width: 528.w,
                    height: 520.w,
                    child: Text(
                      "登录",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 28.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Container(
                    width: 528.w,
                    height: 520.w,
                    padding: EdgeInsets.all(80.w),
                    decoration: const BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(
                          "assets/images/icon_login_back.png",
                        ),
                        fit: BoxFit.fill,
                      ),
                    ),
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          Container(
                            width: double.infinity,
                            margin: EdgeInsets.only(top: 60.w),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.w)),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 25.w,
                                ),
                                Image.asset(
                                  "assets/images/icon_user.png",
                                  width: 25.w,
                                  height: 28.w,
                                ),
                                SizedBox(
                                  width: 200.w,
                                  height: 50.h,
                                  child: RawKeyboardListener(
                                    focusNode: FocusNode(),
                                    onKey: (RawKeyEvent event) {
                                      if (event is RawKeyDownEvent) {
                                        // 处理键盘事件，例如上下左右切换焦点
                                        if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowUp) {
                                          // 处理向上箭头按键
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowDown) {
                                          // 处理向下箭头按键
                                          FocusScope.of(context)
                                              .requestFocus(focusNodePwd);
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowLeft) {
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowRight) {}
                                      }
                                    },
                                    child: Listener(
                                      onPointerDown: (e) =>
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeUser),
                                      child: TextField(
                                        focusNode: focusNodeUser,
                                        textAlign: TextAlign.left,
                                        // enabled: true,
                                        keyboardType: TextInputType.phone,
                                        controller: phoneController,
                                        style: TextStyle(
                                          color: const Color(0xff333333),
                                          fontSize: 17.sp,
                                        ),
                                        inputFormatters: [
                                          LengthLimitingTextInputFormatter(
                                              11), // 限制输入长度为11位
                                        ],

                                        onSubmitted: (_) {
                                          setState(() {
                                            focusNodePwd.requestFocus();
                                          });
                                        },

                                        //将焦点绑定到TextFiled
                                        decoration: InputDecoration(
                                          isCollapsed: false,
                                          hintText: "请输入账户",
                                          hintStyle: TextStyle(
                                            fontSize: 17.sp,
                                            color: const Color(0xff999999),
                                          ),
                                          contentPadding: EdgeInsets.only(
                                              left: 24.w,
                                              right: 20.w,
                                              top: 20.w),
                                          border: const OutlineInputBorder(
                                              borderSide: BorderSide.none),
                                        ),
                                        cursorColor: Colors.blue,
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            width: double.infinity,
                            margin: EdgeInsets.only(top: 30.w),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.w)),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 25.w,
                                ),
                                Image.asset(
                                  "assets/images/icon_pwd.png",
                                  width: 25.w,
                                  height: 28.w,
                                ),
                                SizedBox(
                                  width: 200.w,
                                  height: 50.h,
                                  child: RawKeyboardListener(
                                    focusNode: FocusNode(),
                                    onKey: (RawKeyEvent event) {
                                      if (event is RawKeyDownEvent) {
                                        // 处理键盘事件，例如上下左右切换焦点
                                        if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowUp) {
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeUser);
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowDown) {
                                          // 切换到登录按钮
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeLogin);
                                        }
                                      }
                                    },
                                    child: Listener(
                                      onPointerDown: (e) => {
                                        FocusScope.of(context)
                                            .requestFocus(focusNodePwd),
                                        SystemChannels.textInput
                                            .invokeMethod('TextInput.show'),
                                      },
                                      child: TextField(
                                        // keyboardType: TextInputType.visiblePassword,
                                        focusNode: focusNodePwd,
                                        textAlign: TextAlign.left,
                                        // enabled: true,
                                        keyboardType: TextInputType.text,
                                        // obscureText: true,
                                        // 密码隐藏
                                        controller: pwdController,
                                        style: TextStyle(
                                          color: const Color(0xff333333),
                                          fontSize: 17.sp,
                                        ),
                                        onSubmitted: (_) {
                                          focusNodeLogin.requestFocus();
                                          postLogin();
                                        },
                                        decoration: InputDecoration(
                                          isCollapsed: false,
                                          hintText: "请输入密码",
                                          hintStyle: TextStyle(
                                            fontSize: 17.sp,
                                            color: const Color(0xff999999),
                                          ),
                                          contentPadding: EdgeInsets.only(
                                              left: 24.w,
                                              right: 20.w,
                                              top: 20.w),
                                          border: const OutlineInputBorder(
                                              borderSide: BorderSide.none),
                                        ),
                                        cursorColor: Colors.blue,
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),

                          GestureDetector(
                            onTap: () async {
                              //关闭输入框的焦点
                              FocusManager.instance.primaryFocus!.unfocus();
                              Navigator.of(context).push(MaterialPageRoute(
                                  builder: (context) =>
                                      ForgotPasswordPhonePadPage(
                                          phoneController.text,
                                          currentLanguage)));
                            },
                            child: Container(
                              margin: EdgeInsets.only(top: 10.w),
                              child: Align(
                                alignment: Alignment.centerRight,
                                child: Text(
                                  "重置密码",
                                  style: TextStyle(
                                    color: const Color.fromRGBO(
                                      63,
                                      161,
                                      238,
                                      1,
                                    ),
                                    fontSize: 22.sp,
                                  ),
                                ),
                              ),
                            ),
                          ),

                          SizedBox(
                            height: 30.w,
                          ),

                          // 登录按钮
                          Focus(
                            focusNode: focusNodeLogin,
                            child: GestureDetector(
                              onTap: () {
                                FocusManager.instance.primaryFocus!.unfocus();
                                postLogin();
                              },
                              child: Container(
                                width: double.infinity,
                                height: 60.w,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Colors.blue,
                                  // border: Border.all(
                                  //   color: focusNodeLogin.hasFocus
                                  //       ? Colors.redAccent
                                  //       : Colors.grey,
                                  //   width: 2.0,
                                  // ),
                                  borderRadius: BorderRadius.circular(5.w),
                                ),
                                child: Text(
                                  '登录',
                                  style: TextStyle(
                                    fontSize: 26.sp,
                                    color: Colors.white,
                                  ),
                                  textAlign: TextAlign.center,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Visibility(
            visible: currentLanguage == "en",
            child: Container(
              width: double.infinity,
              height: double.infinity,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(
                    isTable
                        ? "assets/images/icon_pad_main_en_back.png"
                        : "assets/images/icon_phone_main_en_back.png",
                  ),
                  fit: BoxFit.fill,
                ),
              ),
              child: Stack(
                children: [
                  SizedBox(
                    width: 528.w,
                    height: 520.w,
                    child: Text(
                      "Login",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 28.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Container(
                    width: 528.w,
                    height: 520.w,
                    padding: EdgeInsets.all(80.w),
                    decoration: const BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(
                          "assets/images/icon_login_back.png",
                        ),
                        fit: BoxFit.fill,
                      ),
                    ),
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          Container(
                            width: double.infinity,
                            margin: EdgeInsets.only(top: 60.w),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.w)),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 25.w,
                                ),
                                Image.asset(
                                  "assets/images/icon_user.png",
                                  width: 25.w,
                                  height: 28.w,
                                ),
                                SizedBox(
                                  width: 250.w,
                                  height: 50.h,
                                  child: RawKeyboardListener(
                                    focusNode: FocusNode(),
                                    onKey: (RawKeyEvent event) {
                                      if (event is RawKeyDownEvent) {
                                        // 处理键盘事件，例如上下左右切换焦点
                                        if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowUp) {
                                          // 处理向上箭头按键
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowDown) {
                                          // 处理向下箭头按键
                                          FocusScope.of(context)
                                              .requestFocus(focusNodePwd);
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowLeft) {
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowRight) {}
                                      }
                                    },
                                    child: Listener(
                                      onPointerDown: (e) =>
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeUser),
                                      child: TextField(
                                        focusNode: focusNodeUser,
                                        textAlign: TextAlign.left,
                                        // enabled: true,
                                        keyboardType: TextInputType.phone,
                                        controller: phoneController,
                                        style: TextStyle(
                                          color: const Color(0xff333333),
                                          fontSize: 17.sp,
                                        ),
                                        inputFormatters: [
                                          LengthLimitingTextInputFormatter(
                                              11), // 限制输入长度为11位
                                        ],

                                        onSubmitted: (_) {
                                          setState(() {
                                            focusNodePwd.requestFocus();
                                          });
                                        },

                                        //将焦点绑定到TextFiled
                                        decoration: InputDecoration(
                                          isCollapsed: false,
                                          hintText: "account",
                                          hintStyle: TextStyle(
                                            fontSize: 17.sp,
                                            color: const Color(0xff999999),
                                          ),
                                          contentPadding: EdgeInsets.only(
                                              left: 24.w,
                                              right: 20.w,
                                              top: 20.w),
                                          border: const OutlineInputBorder(
                                              borderSide: BorderSide.none),
                                        ),
                                        cursorColor: Colors.blue,
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            width: double.infinity,
                            margin: EdgeInsets.only(top: 30.w),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.w)),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 25.w,
                                ),
                                Image.asset(
                                  "assets/images/icon_pwd.png",
                                  width: 25.w,
                                  height: 28.w,
                                ),
                                SizedBox(
                                  width: 250.w,
                                  height: 50.h,
                                  child: RawKeyboardListener(
                                    focusNode: FocusNode(),
                                    onKey: (RawKeyEvent event) {
                                      if (event is RawKeyDownEvent) {
                                        // 处理键盘事件，例如上下左右切换焦点
                                        if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowUp) {
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeUser);
                                        } else if (event.logicalKey ==
                                            LogicalKeyboardKey.arrowDown) {
                                          // 切换到登录按钮
                                          FocusScope.of(context)
                                              .requestFocus(focusNodeLogin);
                                        }
                                      }
                                    },
                                    child: Listener(
                                      onPointerDown: (e) => {
                                        FocusScope.of(context)
                                            .requestFocus(focusNodePwd),
                                        SystemChannels.textInput
                                            .invokeMethod('TextInput.show'),
                                      },
                                      child: TextField(
                                        // keyboardType: TextInputType.visiblePassword,
                                        focusNode: focusNodePwd,
                                        textAlign: TextAlign.left,
                                        // enabled: true,
                                        keyboardType: TextInputType.text,
                                        // obscureText: true,
                                        // 密码隐藏
                                        controller: pwdController,
                                        style: TextStyle(
                                          color: const Color(0xff333333),
                                          fontSize: 17.sp,
                                        ),
                                        onSubmitted: (_) {
                                          focusNodeLogin.requestFocus();
                                          postLogin();
                                        },
                                        decoration: InputDecoration(
                                          isCollapsed: false,
                                          hintText: "password",
                                          hintStyle: TextStyle(
                                            fontSize: 17.sp,
                                            color: const Color(0xff999999),
                                          ),
                                          contentPadding: EdgeInsets.only(
                                              left: 24.w,
                                              right: 20.w,
                                              top: 20.w),
                                          border: const OutlineInputBorder(
                                              borderSide: BorderSide.none),
                                        ),
                                        cursorColor: Colors.blue,
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),

                          GestureDetector(
                            onTap: () async {
                              //关闭输入框的焦点
                              FocusManager.instance.primaryFocus!.unfocus();
                              Navigator.of(context).push(MaterialPageRoute(
                                  builder: (context) =>
                                      ForgotPasswordPhonePadPage(
                                          phoneController.text,
                                          currentLanguage)));
                            },
                            child: Container(
                              margin: EdgeInsets.only(top: 10.w),
                              child: Align(
                                alignment: Alignment.centerRight,
                                child: Text(
                                  "Reset Password",
                                  style: TextStyle(
                                    color: const Color.fromRGBO(
                                      63,
                                      161,
                                      238,
                                      1,
                                    ),
                                    fontSize: 22.sp,
                                  ),
                                ),
                              ),
                            ),
                          ),

                          SizedBox(
                            height: 30.w,
                          ),

                          // 登录按钮
                          Focus(
                            focusNode: focusNodeLogin,
                            child: GestureDetector(
                              onTap: () {
                                FocusManager.instance.primaryFocus!.unfocus();
                                postLogin();
                              },
                              child: Container(
                                width: double.infinity,
                                height: 60.w,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Colors.blue,
                                  // border: Border.all(
                                  //   color: focusNodeLogin.hasFocus
                                  //       ? Colors.redAccent
                                  //       : Colors.grey,
                                  //   width: 2.0,
                                  // ),
                                  borderRadius: BorderRadius.circular(5.w),
                                ),
                                child: Text(
                                  'Login',
                                  style: TextStyle(
                                    fontSize: 26.sp,
                                    color: Colors.white,
                                  ),
                                  textAlign: TextAlign.center,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Positioned(
            left: 150.w,
            top: 5.w,
            child: Container(
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8.w),
                  border: Border.all(
                    color: const Color.fromRGBO(3, 90, 168, 1),
                    width: 1.w, // 边框宽度
                  )),
              child: Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      SharePreUtils.setLanguage("zh");
                      setState(() {
                        currentLanguage = "zh";
                      });
                    },
                    child: Container(
                      width: 150.w,
                      height: 55.w,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8.w),
                        color: currentLanguage == "zh"
                            ? const Color.fromRGBO(30, 210, 255, 1)
                            : Colors.transparent,
                      ),
                      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
                      child: Text(
                        "中文",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: currentLanguage == "zh"
                              ? const Color.fromRGBO(8, 42, 51, 1)
                              : const Color.fromRGBO(30, 210, 255, 1),
                          fontSize: 28.sp,
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                    ),
                  ),
                  GestureDetector(
                    onTap: () {
                      SharePreUtils.setLanguage("en");
                      setState(() {
                        currentLanguage = "en";
                      });
                    },
                    child: Container(
                      width: 150.w,
                      height: 55.w,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8.w),
                        color: currentLanguage == "en"
                            ? const Color.fromRGBO(30, 210, 255, 1)
                            : Colors.transparent,
                      ),
                      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
                      child: Text(
                        "English",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: currentLanguage == "en"
                              ? const Color.fromRGBO(8, 42, 51, 1)
                              : const Color.fromRGBO(30, 210, 255, 1),
                          fontSize: 28.sp,
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Future<String> getDeviceType() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    String? deviceName;

    if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      deviceName = androidInfo.model;
      bool isTV =
          androidInfo.systemFeatures.contains('android.software.leanback');
      if (isTV == true) {
        return "TV";
      }
    } else if (Platform.isIOS) {
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      deviceName = iosInfo.utsname.machine;
    } else if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
      // 对于桌面设备，可以通过Platform来判断
      if (Platform.isMacOS) {
        deviceName = 'Apple TV'; // 假定Apple TV是基于macOS的
      } else {
        deviceName = 'Unknown';
      }
    }
    print("当前的设备名称 $deviceName");
    // 基于设备名称判断类型
    if (deviceName!.contains('iPad')) {
      return 'iPad';
    } else if (deviceName.contains('iPhone')) {
      return 'iPhone';
    } else if (deviceName.contains('tv')) {
      return 'TV';
    } else {
      if (Device.get().isTablet) {
        return 'Android Pad';
      } else {
        return 'Android';
      }
    }
  }

  void identifyDevice(String type) {
    // //平板 / iPad
    // if (Device.get().isTablet) {
    //   //判断系统
    //   if (Device.get().isIos) {
    //     //iPad
    //   } else {
    //     //平板
    //   }
    //
    //   //直接进入首页  pad版本
    //   Navigator.of(context).pushAndRemoveUntil(
    //       MaterialPageRoute(builder: (context) => const HomePagePad()),
    //       (route) => false);
    // }
    // //手机
    // else if (Device.get().isPhone) {
    //   //直接进入首页  手机版本
    //   Navigator.of(context).pushAndRemoveUntil(
    //       MaterialPageRoute(builder: (context) => const HomePageTest()),
    //       (route) => false);
    // } else {
    //   //直接进入首页  默认 手机版本
    //   Navigator.of(context).pushAndRemoveUntil(
    //       MaterialPageRoute(builder: (context) => const HomePageTest()),
    //       (route) => false);
    // }
    print("当前的类型$type");
    if (type == "iPad" || type == "Android Pad") {
      Navigator.of(context).pushAndRemoveUntil(
          MaterialPageRoute(builder: (context) => const HomePagePad()),
          (route) => false);
    } else if (type == "iPhone" || type == "Android") {
      Navigator.of(context).pushAndRemoveUntil(
          MaterialPageRoute(builder: (context) => const HomePageTV()),
          (route) => false);
    } else if (type == "TV") {
      Navigator.of(context).pushAndRemoveUntil(
          MaterialPageRoute(builder: (context) => const HomePageTV()),
          (route) => false);
    } else {
      Navigator.of(context).pushAndRemoveUntil(
          MaterialPageRoute(builder: (context) => const HomePagePhone()),
          (route) => false);
    }
  }
}
